package com.hexb.smh.config.shiro;

import com.hexb.core.common.ResponseResult;
import com.hexb.smh.exceptions.AccountNotMatchException;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : hexb
 */
@RestControllerAdvice
@Order(1)
public class ShiroExceptionAdvice {

    @ExceptionHandler({UnknownAccountException.class})
    @ResponseStatus(HttpStatus.OK)
    public ResponseResult<?> handleUnknownAccountException() {
        return ResponseResult.unsuccessful("login_failed", "登录失败,帐号或密码错误");
    }

    @ExceptionHandler({DisabledAccountException.class})
    @ResponseStatus(HttpStatus.OK)
    public ResponseResult<?> handleDisabledAccountException() {
        return ResponseResult.unsuccessful("login_failed", "登录失败，该帐号被禁用");
    }

    @ExceptionHandler({AccountNotMatchException.class})
    @ResponseStatus(HttpStatus.OK)
    public ResponseResult<?> handleDisabledAccountNotMatchException() {
        return ResponseResult.unsuccessful("login_failed", "登录失败，帐号类型不匹配");
    }


}
